package com.xjrsoft.module.customer.erp_model.goodsManage.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjrsoft.core.tool.utils.StringUtil;
import com.xjrsoft.module.customer.erp_model.goodsManage.entity.ErpGoods;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.xjrsoft.module.customer.erp_model.goodsManage.dto.ErpGoodsListDto;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.module.customer.erp_model.goodsManage.mapper.ErpGoodsMapper;
import com.xjrsoft.module.customer.erp_model.goodsManage.service.IErpGoodsService;
import com.xjrsoft.core.mp.base.BaseService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 *  服务实现类
 *
 * @author pp
 * @since 2021-10-09
 */
@Service
@AllArgsConstructor
public class ErpGoodsServiceImpl extends BaseService<ErpGoodsMapper, ErpGoods> implements IErpGoodsService {


	@Override
	public IPage<ErpGoods> getPageList(ErpGoodsListDto pageListDto) {
		Wrapper<ErpGoods> wrapper = Wrappers.<ErpGoods>query().lambda()				.like(!StringUtil.isEmpty(pageListDto.getF_EnCode()), ErpGoods::getFEncode, pageListDto.getF_EnCode())
				.like(!StringUtil.isEmpty(pageListDto.getF_FullName()), ErpGoods::getFFullname, pageListDto.getF_FullName())
				.eq(!StringUtil.isEmpty(pageListDto.getF_Id()), ErpGoods::getFGoodscategoryid, pageListDto.getF_Id());
		return this.page(ConventPage.getPage(pageListDto), wrapper);
	}

	@Override
	public String addErpGoods(ErpGoods erpGoods) {
		String erpGoodsId = IdWorker.get32UUID();
		erpGoods.setFId(erpGoodsId);
		boolean isSuccess = this.save(erpGoods);
		return isSuccess ? erpGoodsId : null;
	}

	@Override
	public boolean updateErpGoods(String id, ErpGoods erpGoods) {
		erpGoods.setFId(id);
		return this.updateById(erpGoods);
	}

}
